package zheezes.util;

import java.util.Calendar;
import java.util.Random;

public class RandomUtil {
	private final static String RANDOM_STRING_DICT = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	private static final Random rand = new Random(Calendar.getInstance().getTimeInMillis());

	public static final int randInt(int min, int max) {
		return min + rand.nextInt(max - min);
	}

	public static final int[] randIntArray(int length, int min, int max) {
		int[] array = new int[length];

		for (int i = 0; i < length; i++) {
			array[i] = randInt(min, max);
		}
		return array;
	}

	public static final int[] randUnIntArray(int start, int length) {
		int[] array = new int[length];
		int[] rands = randIntArray(length, 0, length);
		for (int i = 0; i < array.length; i++) {
			array[i] = start + i;
		}
		int idx;
		int tmp;
		for (int i = 0; i < array.length; i++) {
			idx = rands[i];
			if(idx != i) {
				tmp = array[i];
				array[i] = array[idx];
				array[idx] = tmp;
			}
		}
		return array;
	}

	public static final String randString(int size) {
		StringBuffer sb = new StringBuffer();
		int[] array = randIntArray(size, 0, RANDOM_STRING_DICT.length());
		for (int i : array) {
			sb.append(RANDOM_STRING_DICT.charAt(i));
		}
		return sb.toString();
	}
}
